﻿using System.Collections.Generic;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class StoryActionConfig : SerializeCustomConfig
    {
        public int id;
        public string remark;
        public EStoryAction actionType;
        public StoryActionData data;

        public override void Serialize(ByteBuf _buf)
        {
            base.Serialize(_buf);
            _buf.WriteInt(id);
            _buf.WriteString(remark);
            _buf.WriteInt((int)actionType);
            _buf.SerializeObject(data);
        }

        public override void DeSerialize(ByteBuf _buf)
        {
            base.DeSerialize(_buf);
            this.id = _buf.ReadInt();
            this.remark = _buf.ReadString();
            this.actionType = (EStoryAction)_buf.ReadInt();
            this.data = StoryFactoryClient.CreateActionData(actionType);
            _buf.DeSerializeObject(ref data);
        }
    }

    public class StoryActionData : SerializeCustomConfig
    {
    }

    public enum EStoryAction
    {
        [InspectorName("不变")] Hold,
        [InspectorName("移动")] Move,
        [InspectorName("淡入淡出")] Fade,
        [InspectorName("震动")] Shake,
        [InspectorName("大小缩放")] Scale,
        [InspectorName("动画")] Animation,
        [InspectorName("队列")] Queue,
        [InspectorName("并行")] Parallel,
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Move : StoryActionData
    {
        [VisualElementField(true, "移入移出")] public EStoryActionInOut type;
        [VisualElementField(true, "持续时间")] public float duration;
        [VisualElementField(true, "点位")] public int point;
        [VisualElementField(true, "偏移")] public Vector2 shifting;
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Fade : StoryActionData
    {
        [VisualElementField(true, "淡入淡出")] public EStoryActionInOut type;
        [VisualElementField(true, "持续时间")] public float duration;
        [VisualElementField(true, "透明度")] public float alpha;
    }

    public enum EStoryActionInOut
    {
        In,
        Out
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Shake : StoryActionData
    {
        [VisualElementField(true, "持续时间")] public float duration;
        [VisualElementField(true, "范围")] public Vector2 range;
        [VisualElementField(true, "震动速度（次/秒）")]
        public int speed;
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Scale : StoryActionData
    {
        [VisualElementField(true, "缩放")] public float scale;
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Animation : StoryActionData
    {
        [VisualElementField(true, "动作名")] public string animation;
        [VisualElementField(true, "循环")] public bool loop;
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Queue : StoryActionData
    {
        [VisualElementField(true, "行为")] public List<int> actions = new();
    }

    [SerializableGroup(SerializableGroup.StoryActionConfig)]
    public partial class StoryActionData_Parallel : StoryActionData
    {
        [VisualElementField(true, "行为")] public List<int> actions = new();
    }
}